﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="xbrlesita_paring", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(XbrlesitaParing))]
    public class XbrlesitaParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IXbrlesitaParing clazz;
        
        public XbrlesitaParingSerializer(IXbrlesitaParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("yldandmed");
            if (clazz.Yldandmed!=null) {
                global::Xtee.Core.SerializationMetadata metaYldandmed = this.GetMetaData(clazz.Yldandmed);
                Writer.WriteTypeAttribute(metaYldandmed.TypeQualifiedName.Namespace, metaYldandmed.TypeQualifiedName.Name);
                metaYldandmed.NewSerializer(clazz.Yldandmed).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Yldandmed");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("sidevahendid");
            if (clazz.Sidevahendid!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("xbrlesita_sidevahend", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Sidevahendid.Count);
                for (int x = 0; ((clazz.Sidevahendid != null) 
                            && (x < clazz.Sidevahendid.Count)); x = (x + 1)) {
                    if (clazz.Sidevahendid[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaSidevahendid = this.GetMetaData(clazz.Sidevahendid[x]);
                        Writer.WriteTypeAttribute(metaSidevahendid.TypeQualifiedName.Namespace, metaSidevahendid.TypeQualifiedName.Name);
                        metaSidevahendid.NewSerializer(clazz.Sidevahendid[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("osanikud");
            if (clazz.Osanikud!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("xbrlesita_osanik", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Osanikud.Count);
                for (int x = 0; ((clazz.Osanikud != null) 
                            && (x < clazz.Osanikud.Count)); x = (x + 1)) {
                    if (clazz.Osanikud[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaOsanikud = this.GetMetaData(clazz.Osanikud[x]);
                        Writer.WriteTypeAttribute(metaOsanikud.TypeQualifiedName.Namespace, metaOsanikud.TypeQualifiedName.Name);
                        metaOsanikud.NewSerializer(clazz.Osanikud[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("myygitulu");
            if (clazz.Myygitulu!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("xbrlesita_myygitulu_rida", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Myygitulu.Count);
                for (int x = 0; ((clazz.Myygitulu != null) 
                            && (x < clazz.Myygitulu.Count)); x = (x + 1)) {
                    if (clazz.Myygitulu[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaMyygitulu = this.GetMetaData(clazz.Myygitulu[x]);
                        Writer.WriteTypeAttribute(metaMyygitulu.TypeQualifiedName.Namespace, metaMyygitulu.TypeQualifiedName.Name);
                        metaMyygitulu.NewSerializer(clazz.Myygitulu[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("manused");
            if (clazz.Manused!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("string", "http://www.w3.org/2001/XMLSchema", clazz.Manused.Count);
                for (int x = 0; ((clazz.Manused != null) 
                            && (x < clazz.Manused.Count)); x = (x + 1)) {
                    if (clazz.Manused[x]!=null) {
                        Writer.WriteStartElement("item");
                        Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Manused[x]))).ToString());
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Manused");
            }
            Writer.WriteEndElement();
            if (clazz.Audiitorid!=null) {
                Writer.WriteStartElement("audiitorid");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("xbrlesita_audiitor", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.Audiitorid.Count);
                for (int x = 0; ((clazz.Audiitorid != null) 
                            && (x < clazz.Audiitorid.Count)); x = (x + 1)) {
                    if (clazz.Audiitorid[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaAudiitorid = this.GetMetaData(clazz.Audiitorid[x]);
                        Writer.WriteTypeAttribute(metaAudiitorid.TypeQualifiedName.Namespace, metaAudiitorid.TypeQualifiedName.Name);
                        metaAudiitorid.NewSerializer(clazz.Audiitorid[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("xbrlinfo");
            if (clazz.Xbrlinfo!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Xbrlinfo))).ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="yldandmed") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_paring>yldandmed");
                }
                global::Xtee.Core.SerializationMetadata metaYldandmed = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaYldandmed>(Reader, "xbrlesita_yldandmed", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                clazz.Yldandmed = metaYldandmed.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaYldandmed>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("yldandmed");
                    metaYldandmed.NewSerializer(clazz.Yldandmed).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrlesita_paring>yldandmed", Reader.LocalName);
            }
            if (Reader.LocalName=="sidevahendid") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Sidevahendid = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaSidevahend>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("sidevahendid");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_sidevahendid>item");
                            }
                            global::Xtee.Core.SerializationMetadata metaSidevahendid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaSidevahend>(Reader, "xbrlesita_sidevahend", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                            global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaSidevahend item = metaSidevahendid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaSidevahend>();
                            clazz.Sidevahendid.Add(item);
                            if ((Reader.IsEmptyElement == false)) {
                                Reader.ReadStartElement("item");
                                metaSidevahendid.NewSerializer(item).ReadXml(Reader);
                                Reader.ReadEndElement();
                            }
                            else {
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrlesita_paring>sidevahendid", Reader.LocalName);
            }
            if (Reader.LocalName=="osanikud") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Osanikud = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaOsanik>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("osanikud");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_osanikud>item");
                            }
                            global::Xtee.Core.SerializationMetadata metaOsanikud = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaOsanik>(Reader, "xbrlesita_osanik", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                            global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaOsanik item = metaOsanikud.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaOsanik>();
                            clazz.Osanikud.Add(item);
                            if ((Reader.IsEmptyElement == false)) {
                                Reader.ReadStartElement("item");
                                metaOsanikud.NewSerializer(item).ReadXml(Reader);
                                Reader.ReadEndElement();
                            }
                            else {
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrlesita_paring>osanikud", Reader.LocalName);
            }
            if (Reader.LocalName=="myygitulu") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Myygitulu = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaMyygituluRida>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("myygitulu");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_myygitulu>item");
                            }
                            global::Xtee.Core.SerializationMetadata metaMyygitulu = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaMyygituluRida>(Reader, "xbrlesita_myygitulu_rida", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                            global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaMyygituluRida item = metaMyygitulu.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaMyygituluRida>();
                            clazz.Myygitulu.Add(item);
                            if ((Reader.IsEmptyElement == false)) {
                                Reader.ReadStartElement("item");
                                metaMyygitulu.NewSerializer(item).ReadXml(Reader);
                                Reader.ReadEndElement();
                            }
                            else {
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrlesita_paring>myygitulu", Reader.LocalName);
            }
            if (Reader.LocalName=="manused") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_paring>manused");
                }
                clazz.Manused = new System.Collections.Generic.List<System.String>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("manused");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_dokumendid>item");
                        }
                        clazz.Manused.Add(new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("item")).Value);
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrlesita_paring>manused", Reader.LocalName);
            }
            if (Reader.LocalName=="audiitorid") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Audiitorid = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaAudiitor>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("audiitorid");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrlesita_audiitorid>item");
                            }
                            global::Xtee.Core.SerializationMetadata metaAudiitorid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaAudiitor>(Reader, "xbrlesita_audiitor", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                            global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaAudiitor item = metaAudiitorid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlesitaAudiitor>();
                            clazz.Audiitorid.Add(item);
                            if ((Reader.IsEmptyElement == false)) {
                                Reader.ReadStartElement("item");
                                metaAudiitorid.NewSerializer(item).ReadXml(Reader);
                                Reader.ReadEndElement();
                            }
                            else {
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="xbrlinfo") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.Xbrlinfo = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("xbrlinfo")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrlesita_paring>xbrlinfo", Reader.LocalName);
            }
        }
    }
}
